package com.sihai.ehr.web.action.employee;

import com.sihai.core.LimitedList;
import com.sihai.core.beans.BeanInject;
import com.sihai.core.utils.RangeUtils;
import com.sihai.ehr.model.biz.*;
import com.sihai.ehr.model.sys.Organization;
import com.sihai.ehr.service.EmployeeService;
import com.sihai.ehr.service.OrganizationService;
import com.sihai.ehr.service.ResignService;
import com.sihai.ehr.utils.DateUtil;
import com.sihai.ehr.utils.StringUtil;
import com.sihai.ehr.web.action.EHRAction;
import com.sihai.ehr.web.pojo.StaffSearchPojo;
import org.apache.commons.lang.xwork.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import java.util.*;

@Results({@Result(name = "list", location = "talent_list.jsp"),
        @Result(name = "add", location = "talent_add.jsp"),
        @Result(name = "view", location = "talent_view.jsp"),
        @Result(name = "edit", location = "talent_modify.jsp"),
        @Result(name = "main", location = "talent_main.jsp"),
        @Result(name = "talentedu_list", location = "edu_list.jsp"),
        @Result(name = "talenttrain_list", location = "train_list.jsp"),
        @Result(name = "talentexp_list", location = "exp_list.jsp"),
        @Result(name = "talentfamily_list", location = "family_list.jsp")
})
public class TalentRepoAction extends EHRAction {

    @BeanInject
    private OrganizationService organizationService;
    @BeanInject
    private EmployeeService employeeService;

    private List<Organization> organizations;
    private LimitedList<EmployeeinfoBase> employeeinfoBases;
    private EmployeeinfoBase employeeinfoBase;
    private EmployeeinfoEducation employeeinfoEducation;
    private EmployeeinfoTrain employeeinfoTrain;
    private EmployeeWorkExperience employeeWorkExperience;
    private EmployeeinfoFamily employeeinfoFamily;

    private List<EmployeeinfoEducation> employeeinfoEducationList;
    private List<EmployeeinfoTrain> employeeinfoTrains;
    private List<EmployeeWorkExperience> employeeWorkExperiences;
    private List<EmployeeinfoFamily> employeeinfoFamilies;
    private Long id;
    private String empIds;
    private String talentName;//人才库姓名模糊搜索
    private StaffSearchPojo pojo;
    private Integer eduSize;
    private Long eduId;
    //人才库删除功能
    private int state;

    @Override
    @Action("/employee/talent_main")
    public String execute() throws Exception {
        listAction = "/employee/talent_list.xhtml";
        listTitle = "人才储备库";
        showChildOrg = true;
        organizations = organizationService.findChildren(null, true, null, null);
        if (organizations != null && organizations.size() > 0) {
        	if(getCurrentUserId() > 0){
            	Long topOrgId = getCurrentUser().getWork().getOrganization().getTopOrganization().getId();
            	Iterator<Organization> it = organizations.iterator();
            	while(it.hasNext()){
            		Organization o = it.next();
            		if(o.getId() != topOrgId){
            			it.remove();
            		}
            	}
            }
            organizationId = organizations.get(0).getId();
        }
        return "main";
    }

    @Action("/employee/talent_list")
    public String list() throws Exception {

        if (talentName != null && talentName.trim().length() > 0) {
            employeeinfoBase = new EmployeeinfoBase(talentName);
        }
        employeeinfoBases = employeeService.searchEmployeeinfoBase(employeeinfoBase, 3, createLimit(), createSorter());

        //分页
        this.paging(employeeinfoBases);
        this.setPageUrl("employee/talent_list.xhtml");

        return "list";
    }

    @Action(value = "/employee/talent_add")
    public String add() throws Exception {
        removeSessions();
        long start = System.currentTimeMillis();
        ServletActionContext.getRequest().getSession().setAttribute("startTime", start); //设置开始时间
        return "add";
    }

    @Action(value = "/employee/talent_edit")
    public String edit() throws Exception {
        removeSessions();
        employeeinfoBase = employeeService.getEmployeeinfoBase(id);
        employeeinfoEducationList = employeeService.getEducationList(employeeinfoBase, null, null);
        eduSize = employeeinfoEducationList.size();
        employeeinfoTrains = employeeService.getTrainList(employeeinfoBase, null, null);
        employeeWorkExperiences = employeeService.getWorkExperienceList(employeeinfoBase, null, null);
        employeeinfoFamilies = employeeService.getEmployeeFamilyList(employeeinfoBase, null, null);
        long start = System.currentTimeMillis();
        ServletActionContext.getRequest().getSession().setAttribute("startTime", start); //设置开始时间
        return "edit";
    }

    @Action(value = "/employee/talent_create", results = {
            @Result(name = "success", type = "json", params = {"root", "pojo"})
    })
    public String create() throws Exception {
        //保存员工基本信息
        if (employeeinfoBase != null && employeeinfoBase.getId() != null) {
            EmployeeinfoBase base = employeeService.getEmployeeinfoBase(employeeinfoBase.getId());
            base.setName(employeeinfoBase.getName());
            base.setAddress(employeeinfoBase.getAddress());
            base.setArchives(employeeinfoBase.getArchives());
            base.setAvoirdupois(employeeinfoBase.getAvoirdupois());
            base.setBaby(employeeinfoBase.getBaby());
            base.setBirthday(employeeinfoBase.getBirthday());
            base.setCensus(employeeinfoBase.getCensus());
            base.setCertificate(employeeinfoBase.getCertificate());
            base.setCompensation(employeeinfoBase.getCompensation());
            base.setEmail(employeeinfoBase.getEmail());
            base.setEnglishDialog(employeeinfoBase.getEnglishDialog());
            base.setEnglishLetter(employeeinfoBase.getEnglishLetter());
            base.setEnglishRead(employeeinfoBase.getEnglishRead());
            base.setEnglishWrite(employeeinfoBase.getEnglishWrite());
            base.setEntryDate(employeeinfoBase.getEntryDate());
            base.setEyeLeft(employeeinfoBase.getEyeLeft());
            base.setEyeRight(employeeinfoBase.getEyeRight());
            base.setLanguageDialog(employeeinfoBase.getLanguageDialog());
            base.setLanguageLetter(employeeinfoBase.getLanguageLetter());
            base.setLanguageRead(employeeinfoBase.getLanguageRead());
            base.setLanguageWrite(employeeinfoBase.getLanguageWrite());
            base.setFacePath(employeeinfoBase.getFacePath());
            base.setRemark(employeeinfoBase.getRemark());
            base.setPostcode(employeeinfoBase.getPostcode());
            base.setSchool(employeeinfoBase.getSchool());
            base.setSex(employeeinfoBase.getSex());
            base.setStature(employeeinfoBase.getStature());
            base.setTech(employeeinfoBase.getTech());
            base.setTel(employeeinfoBase.getTel());
            base.setHandSet(employeeinfoBase.getHandSet());
            base.setMarry(employeeinfoBase.getMarry());
            base.setFolk(employeeinfoBase.getFolk());
            base.setWorkAge(employeeinfoBase.getWorkAge());
            base.setSuggestDuty(employeeinfoBase.getSuggestDuty());
            employeeService.updateEmployeeRelatedEntity(base);
        } else {
            employeeinfoBase.setState("3");
            employeeinfoBase.setCancel("0");
            employeeService.saveEmployeeBase(employeeinfoBase);
        }
        //保存教育情况
        Object objs = ServletActionContext.getRequest().getSession().getAttribute("eduList");
        if (objs != null) {
            Map<Long, EmployeeinfoEducation> edus = (Map<Long, EmployeeinfoEducation>) objs;
            if (!edus.isEmpty()) {
                Set<Map.Entry<Long, EmployeeinfoEducation>> set = edus.entrySet();
                Iterator<Map.Entry<Long, EmployeeinfoEducation>> it = set.iterator();
                while (it.hasNext()) {
                    Map.Entry<Long, EmployeeinfoEducation> entry = it.next();
                    Long id = entry.getKey();
                    EmployeeinfoEducation edu = employeeService.getEmployeeinfoEducationById(id);
                    if (edu != null) {
                        EmployeeinfoEducation temp=entry.getValue();
                        edu.setSchoolName(temp.getSchoolName());
                        edu.setSpecialty(temp.getSpecialty());
                        edu.setDegree(temp.getDegree());
                        edu.setBeginDate(temp.getBeginDate());
                        edu.setEndDate(temp.getEndDate());
                        edu.setDiffMon(temp.getDiffMon());
                        edu.setBaseId(employeeinfoBase);
                        employeeService.updateEmployeeRelatedEntity(edu);
                    } else {
                        EmployeeinfoEducation temp=entry.getValue();
                        temp.setId(null);
                        temp.setBaseId(employeeinfoBase);
                        employeeService.saveEducation(temp);
                    }
                }

            }
        }
        //保存培训信息
        objs = ServletActionContext.getRequest().getSession().getAttribute("trainList");
        if (objs != null) {
            Map<Long, EmployeeinfoTrain> train_maps = (Map<Long, EmployeeinfoTrain>) objs;
            if (!train_maps.isEmpty()) {
                Set<Map.Entry<Long, EmployeeinfoTrain>> set = train_maps.entrySet();
                Iterator<Map.Entry<Long, EmployeeinfoTrain>> it = set.iterator();
                while (it.hasNext()) {
                    Map.Entry<Long, EmployeeinfoTrain> entry = (Map.Entry<Long, EmployeeinfoTrain>) it.next();
                    Long id = entry.getKey();
                    EmployeeinfoTrain train = employeeService.getEmployeeinfoTrainById(id);
                    if (train != null) {
                        EmployeeinfoTrain temp=entry.getValue();
                        train.setBeginDate(temp.getBeginDate());
                        train.setEndDate(temp.getEndDate());
                        train.setDiffMon(temp.getDiffMon());
                        train.setLetter(temp.getLetter());
                        train.setTrainAddress(temp.getTrainAddress());
                        train.setTrainContent(temp.getTrainContent());
                        train.setBaseId(employeeinfoBase);
                        employeeService.updateEmployeeRelatedEntity(train);
                    } else {
                        EmployeeinfoTrain temp=entry.getValue();
                        temp.setId(null);
                        temp.setBaseId(employeeinfoBase);
                        employeeService.saveEmployeeTrain(temp);
                    }
                }

            }
        }
        //保存工作经历
        objs = ServletActionContext.getRequest().getSession().getAttribute("expList");
        if (objs != null) {
            Map<Long, EmployeeWorkExperience> exps = (Map<Long, EmployeeWorkExperience>) objs;
            if (!exps.isEmpty()) {
                Set<Map.Entry<Long, EmployeeWorkExperience>> set = exps.entrySet();
                Iterator<Map.Entry<Long, EmployeeWorkExperience>> it = set.iterator();
                while (it.hasNext()) {
                    Map.Entry<Long, EmployeeWorkExperience> entry = it.next();
                    Long id = entry.getKey();
                    EmployeeWorkExperience exp = employeeService.getEmployeeWorkExperienceById(id);
                    if (exp != null) {
                        EmployeeWorkExperience temp=entry.getValue();
                        exp.setBeginDate(temp.getBeginDate());
                        exp.setEndDate(temp.getEndDate());
                        exp.setCompname(temp.getCompname());
                        exp.setContel(temp.getContel());
                        exp.setDiffMon(temp.getDiffMon());
                        exp.setJob(temp.getJob());
                        exp.setMonthlyPay(temp.getMonthlyPay());
                        exp.setProveMan(temp.getProveMan());
                        exp.setResignReason(temp.getResignReason());
                        exp.setEmployeeinfoBase(employeeinfoBase);
                        employeeService.updateEmployeeRelatedEntity(exp);
                    } else {
                        EmployeeWorkExperience temp=entry.getValue();
                        temp.setId(null);
                        temp.setEmployeeinfoBase(employeeinfoBase);
                        employeeService.saveEmployeeExperience(temp);
                    }
                }

            }

        }
        //保存家庭情况
        objs = ServletActionContext.getRequest().getSession().getAttribute("familyList");
        if (objs != null) {
            Map<Long, EmployeeinfoFamily> famlies = (Map<Long, EmployeeinfoFamily>) objs;
            if (!famlies.isEmpty()) {
                Set<Map.Entry<Long, EmployeeinfoFamily>> set = famlies.entrySet();
                Iterator<Map.Entry<Long, EmployeeinfoFamily>> it = set.iterator();
                while (it.hasNext()) {
                    Map.Entry<Long, EmployeeinfoFamily> entry = it.next();
                    Long id = entry.getKey();
                    EmployeeinfoFamily family = employeeService.getEmployeeFamilyById(id);
                    if (family != null) {
                        EmployeeinfoFamily temp= entry.getValue();
                        family.setAddress(temp.getAddress());
                        family.setCompname(temp.getCompname());
                        family.setContel(temp.getContel());
                        family.setExigenceConname(temp.getExigenceConname());
                        family.setExigenceRelation(temp.getExigenceRelation());
                        family.setFamilyRelation(temp.getFamilyRelation());
                        family.setName(temp.getName());
                        family.setEmployeeinfoBase(employeeinfoBase);
                        employeeService.updateEmployeeRelatedEntity(family);
                    } else {
                        EmployeeinfoFamily temp= entry.getValue();
                        temp.setId(null);
                        temp.setEmployeeinfoBase(employeeinfoBase);
                        employeeService.saveEmployeeFamily(temp);
                    }
                }

            }
        }
        //获取输入用时
        long start = (Long) ServletActionContext.getRequest().getSession().getAttribute("startTime");
        long end = System.currentTimeMillis();
        String totalTime = DateUtil.getDiffDate(start, end);
        String userName = employeeinfoBase.getName();
        pojo = new StaffSearchPojo(userName, totalTime);
        //清空session
        removeSessions();
        return SUCCESS;
    }

    @Action(value = "/employee/talentedu_list")
    public String education() throws Exception {
        if (employeeinfoEducation != null)
            employeeinfoEducation.setDiffMon(DateUtil.getMonthsOfAge(employeeinfoEducation.getBeginDate(), employeeinfoEducation.getEndDate()));
        //存放新增的教育情况和已有的教育情况，key为education id
        Map<Long, EmployeeinfoEducation> edu_maps = new HashMap<Long, EmployeeinfoEducation>();
        Object obj = ServletActionContext.getRequest().getSession().getAttribute("eduList");
        if (obj == null) {
            if (employeeinfoEducation.getId() == null) {
                Long tempId = StringUtil.getTempNo();
                edu_maps.put(tempId, employeeinfoEducation);
            } else {
                edu_maps.put(employeeinfoEducation.getId(), employeeinfoEducation);
            }

        } else {
            edu_maps = (Map<Long, EmployeeinfoEducation>) obj;
            if (employeeinfoEducation.getId() == null) {
                Long tempId = StringUtil.getTempNo();
                edu_maps.put(tempId, employeeinfoEducation);
            } else {
                edu_maps.put(employeeinfoEducation.getId(), employeeinfoEducation);
            }
        }
        ServletActionContext.getRequest().getSession().setAttribute("eduList", edu_maps);
        if (!edu_maps.isEmpty()) {
            List<EmployeeinfoEducation> edus = new ArrayList<EmployeeinfoEducation>();
            Set<Map.Entry<Long, EmployeeinfoEducation>> set = edu_maps.entrySet();
            Iterator<Map.Entry<Long, EmployeeinfoEducation>> it = set.iterator();
            while (it.hasNext()) {
                Map.Entry<Long, EmployeeinfoEducation> entry = it.next();
                EmployeeinfoEducation edu = entry.getValue();
                edu.setId(entry.getKey());
                edus.add(edu);
            }

            employeeinfoEducationList = new ArrayList<EmployeeinfoEducation>();
            for (EmployeeinfoEducation edu : edus) {
                edu.setBeginDateStr(DateUtil.getStrByDate(edu.getBeginDate(), "yyyy年MM月"));
                edu.setEndDateStr(DateUtil.getStrByDate(edu.getEndDate(), "yyyy年MM月"));
                employeeinfoEducationList.add(edu);
            }
            if(employeeinfoBase.getId()!=null){
                List<EmployeeinfoEducation> dataEdus = employeeService.getEducationList(employeeinfoBase, null, null);
                if (dataEdus != null && dataEdus.size() > 0) {
                    for (EmployeeinfoEducation edu : dataEdus) {
                        if(edu_maps.get(edu.getId())!=null){
                            continue;
                        }
                        edu.setBeginDateStr(DateUtil.getStrByDate(edu.getBeginDate(), "yyyy年MM月"));
                        edu.setEndDateStr(DateUtil.getStrByDate(edu.getEndDate(), "yyyy年MM月"));
                        employeeinfoEducationList.add(edu);
                    }
                }
            }
        }

        return "talentedu_list";
    }


    @Action(value = "/employee/talenttrain_list")
    public String train() throws Exception {
        if (employeeinfoTrain != null)
            employeeinfoTrain.setDiffMon(DateUtil.getMonthsOfAge(employeeinfoTrain.getBeginDate(), employeeinfoTrain.getEndDate()));

        Map<Long, EmployeeinfoTrain> train_maps = new HashMap<Long, EmployeeinfoTrain>();
        Object obj = ServletActionContext.getRequest().getSession().getAttribute("trainList");
        if (obj == null) {
            if (employeeinfoTrain.getId() == null) {
                Long tempId = StringUtil.getTempNo();
                train_maps.put(tempId, employeeinfoTrain);
            } else {
                train_maps.put(employeeinfoTrain.getId(), employeeinfoTrain);
            }

        } else {
            train_maps = (Map<Long, EmployeeinfoTrain>) obj;
            if (employeeinfoTrain.getId() == null) {
                Long tempId = StringUtil.getTempNo();
                train_maps.put(tempId, employeeinfoTrain);
            } else {
                train_maps.put(employeeinfoTrain.getId(), employeeinfoTrain);
            }
        }
        ServletActionContext.getRequest().getSession().setAttribute("trainList", train_maps);
        if (!train_maps.isEmpty()) {
            List<EmployeeinfoTrain> trains = new ArrayList<EmployeeinfoTrain>();
            Set<Map.Entry<Long, EmployeeinfoTrain>> set = train_maps.entrySet();
            Iterator<Map.Entry<Long, EmployeeinfoTrain>> it = set.iterator();
            while (it.hasNext()) {
                Map.Entry<Long, EmployeeinfoTrain> entry = it.next();
                EmployeeinfoTrain train = entry.getValue();
                train.setId(entry.getKey());
                trains.add(train);
            }
            employeeinfoTrains = new ArrayList<EmployeeinfoTrain>();
            for (EmployeeinfoTrain train : trains) {
                train.setBeginDateStr(DateUtil.getStrByDate(train.getBeginDate(), "yyyy年MM月"));
                train.setEndDateStr(DateUtil.getStrByDate(train.getEndDate(), "yyyy年MM月"));
                employeeinfoTrains.add(train);
            }
            if(employeeinfoBase.getId()!=null){
                List<EmployeeinfoTrain> dataTrain = employeeService.getTrainList(employeeinfoBase, null, null);
                if (dataTrain != null && dataTrain.size() > 0) {
                    for (EmployeeinfoTrain train : dataTrain) {
                        if(train_maps.get(train.getId())!=null){
                            continue;
                        }
                        train.setBeginDateStr(DateUtil.getStrByDate(train.getBeginDate(), "yyyy年MM月"));
                        train.setEndDateStr(DateUtil.getStrByDate(train.getEndDate(), "yyyy年MM月"));
                    }
                }
            }
        }
        return "talenttrain_list";
    }


    @Action(value = "/employee/talentexp_list")
    public String experience1() throws Exception {
        if (employeeWorkExperience != null)
            employeeWorkExperience.setDiffMon(DateUtil.getMonthsOfAge(employeeWorkExperience.getBeginDate(), employeeWorkExperience.getEndDate()));
        Map<Long, EmployeeWorkExperience> exp_maps = new HashMap<Long, EmployeeWorkExperience>();
        Object obj = ServletActionContext.getRequest().getSession().getAttribute("expList");
        if (obj == null) {
            if (employeeWorkExperience.getId() == null) {
                Long tempId = StringUtil.getTempNo();
                exp_maps.put(tempId, employeeWorkExperience);
            } else {
                exp_maps.put(employeeWorkExperience.getId(), employeeWorkExperience);
            }
        } else {
            exp_maps = (Map<Long, EmployeeWorkExperience>) obj;
            if (employeeWorkExperience.getId() == null) {
                Long tempId = StringUtil.getTempNo();
                exp_maps.put(tempId, employeeWorkExperience);
            } else {
                exp_maps.put(employeeWorkExperience.getId(), employeeWorkExperience);
            }
        }
        ServletActionContext.getRequest().getSession().setAttribute("expList", exp_maps);
        if (!exp_maps.isEmpty()) {
            List<EmployeeWorkExperience> exps = new ArrayList<EmployeeWorkExperience>();
            Set<Map.Entry<Long, EmployeeWorkExperience>> set = exp_maps.entrySet();
            Iterator<Map.Entry<Long, EmployeeWorkExperience>> it = set.iterator();
            while (it.hasNext()) {
                Map.Entry<Long, EmployeeWorkExperience> entry = it.next();
                EmployeeWorkExperience exp = entry.getValue();
                exp.setId(entry.getKey());
                exps.add(exp);
            }
            employeeWorkExperiences = new ArrayList<EmployeeWorkExperience>();
            for (EmployeeWorkExperience exp : exps) {
                exp.setBeginDateStr(DateUtil.getStrByDate(exp.getBeginDate(), "yyyy年MM月"));
                exp.setEndDateStr(DateUtil.getStrByDate(exp.getEndDate(), "yyyy年MM月"));
                employeeWorkExperiences.add(exp);
            }
            if(employeeinfoBase.getId()!=null){
                List<EmployeeWorkExperience> dataExp = employeeService.getWorkExperienceList(employeeinfoBase, null, null);
                if (dataExp != null && dataExp.size() > 0) {
                    for (EmployeeWorkExperience exp : dataExp) {
                        if(exp_maps.get(exp.getId())!=null){
                            continue;
                        }
                        exp.setBeginDateStr(DateUtil.getStrByDate(exp.getBeginDate(), "yyyy年MM月"));
                        exp.setEndDateStr(DateUtil.getStrByDate(exp.getEndDate(), "yyyy年MM月"));
                        employeeWorkExperiences.add(exp);
                    }
                }
            }
        }
        return "talentexp_list";
    }

    @Action(value = "/employee/talentfamily_list")
    public String family() throws Exception {
        Map<Long, EmployeeinfoFamily> fam_maps = new HashMap<Long, EmployeeinfoFamily>();
        Object obj = ServletActionContext.getRequest().getSession().getAttribute("familyList");
        if (obj == null) {
            if (employeeinfoFamily.getId() == null) {
                Long tempId = StringUtil.getTempNo();
                fam_maps.put(tempId, employeeinfoFamily);
            } else {
                fam_maps.put(employeeinfoFamily.getId(), employeeinfoFamily);
            }
        } else {
            fam_maps = (Map<Long, EmployeeinfoFamily>) obj;
            if (employeeinfoFamily.getId() == null) {
                Long tempId = StringUtil.getTempNo();
                fam_maps.put(tempId, employeeinfoFamily);
            } else {
                fam_maps.put(employeeinfoFamily.getId(), employeeinfoFamily);
            }
        }
        ServletActionContext.getRequest().getSession().setAttribute("familyList", fam_maps);
        if (!fam_maps.isEmpty()) {
            employeeinfoFamilies = new ArrayList<EmployeeinfoFamily>();
            Set<Map.Entry<Long, EmployeeinfoFamily>> set = fam_maps.entrySet();
            Iterator<Map.Entry<Long, EmployeeinfoFamily>> it = set.iterator();
            while (it.hasNext()) {
                Map.Entry<Long, EmployeeinfoFamily> entry = it.next();
                EmployeeinfoFamily family = entry.getValue();
                family.setId(entry.getKey());
                employeeinfoFamilies.add(family);
            }
        }
        if(employeeinfoBase.getId()!=null){
            List<EmployeeinfoFamily> dataFamily = employeeService.getEmployeeFamilyList(employeeinfoBase, null, null);
            if(dataFamily!=null && dataFamily.size()>0){
                for(EmployeeinfoFamily family:dataFamily){
                    if(fam_maps.get(family.getId())!=null){
                        continue;
                    }
                    employeeinfoFamilies.add(family);
                }
            }
        }
        
        return "talentfamily_list";
    }

    @Action(value = "/employee/talent_delete")
    public String delete() throws Exception {
        if (StringUtils.isBlank(empIds)) {
            return list();
        }
        employeeService.removeEmployee(empIds, 2);
        return list();
    }

    @Action(value = "/employee/talent_view")
    public String view() throws Exception {
        employeeinfoBase = employeeService.getEmployeeinfoBase(id);
        employeeinfoEducationList = employeeService.getEducationList(employeeinfoBase, null, null);
        employeeinfoTrains = employeeService.getTrainList(employeeinfoBase, null, null);
        employeeWorkExperiences = employeeService.getWorkExperienceList(employeeinfoBase, null, null);
        employeeinfoFamilies = employeeService.getEmployeeFamilyList(employeeinfoBase, null, null);
        return "view";
    }

    @Action(value = "/employee/getTalentEduinfoById", results = {
            @Result(name = "success", type = "json", params = {"root", "employeeinfoEducation"})
    })
    public String modify_education() throws Exception {
        Object obj = ServletActionContext.getRequest().getSession().getAttribute("eduList");
        if(obj!=null) {
            Map<Long, EmployeeinfoEducation> edu_maps = (Map<Long, EmployeeinfoEducation>) obj;
            employeeinfoEducation = edu_maps.get(eduId);
            if(employeeinfoEducation==null)
                  employeeinfoEducation =employeeService.getEmployeeinfoEducationById(eduId);
        }else{
            employeeinfoEducation=employeeService.getEmployeeinfoEducationById(eduId);
        }
        if (employeeinfoEducation != null) {
                employeeinfoEducation.setBeginDateStr(DateUtil.getStrByDate(employeeinfoEducation.getBeginDate(), "yyyy-MM-dd"));
                employeeinfoEducation.setEndDateStr(DateUtil.getStrByDate(employeeinfoEducation.getEndDate(), "yyyy-MM-dd"));
        }

        return SUCCESS;
    }

    @Action(value = "/employee/getTalentTraininfoById", results = {
            @Result(name = "success", type = "json", params = {"root", "employeeinfoTrain"})
    })
    public String modify_train() throws Exception {
        Object obj = ServletActionContext.getRequest().getSession().getAttribute("trainList");
        if(obj!=null){
            Map<Long, EmployeeinfoTrain> train_maps = (Map<Long, EmployeeinfoTrain>) obj;
            employeeinfoTrain = train_maps.get(eduId);
            if(employeeinfoTrain==null)  //如果内存中不存在，就查找数据库
                employeeinfoTrain=employeeService.getEmployeeinfoTrainById(eduId);
        }else{
            employeeinfoTrain=employeeService.getEmployeeinfoTrainById(eduId);
        }
        if (employeeinfoTrain != null) {
            employeeinfoTrain.setBeginDateStr(DateUtil.getStrByDate(employeeinfoTrain.getBeginDate(), "yyyy-MM-dd"));
            employeeinfoTrain.setEndDateStr(DateUtil.getStrByDate(employeeinfoTrain.getEndDate(), "yyyy-MM-dd"));
        }
        return SUCCESS;
    }

    @Action(value = "/employee/getTalentExperienceById", results = {
            @Result(name = "success", type = "json", params = {"root", "employeeWorkExperience"})
    })
    public String modify_experience() throws Exception {
        Object obj = ServletActionContext.getRequest().getSession().getAttribute("expList");
        if(obj!=null){
            Map<Long, EmployeeWorkExperience> exp_maps = (Map<Long, EmployeeWorkExperience>) obj;
            employeeWorkExperience = exp_maps.get(eduId);
            if(employeeWorkExperience==null)
                employeeWorkExperience=employeeService.getEmployeeWorkExperienceById(eduId);
        }else{
            employeeWorkExperience=employeeService.getEmployeeWorkExperienceById(eduId);
        }
        if (employeeWorkExperience != null) {
            employeeWorkExperience.setBeginDateStr(DateUtil.getStrByDate(employeeWorkExperience.getBeginDate(), "yyyy-MM-dd"));
            employeeWorkExperience.setEndDateStr(DateUtil.getStrByDate(employeeWorkExperience.getEndDate(), "yyyy-MM-dd"));
        }
        return SUCCESS;
    }

    @Action(value = "/employee/getTalentFamilyById", results = {
            @Result(name = "success", type = "json", params = {"root", "employeeinfoFamily"})
    })
    public String modify_family() throws Exception {
        Object obj = ServletActionContext.getRequest().getSession().getAttribute("familyList");
        if(obj!=null){
            Map<Long, EmployeeinfoFamily> fam_maps = (Map<Long, EmployeeinfoFamily>) obj;
            employeeinfoFamily = fam_maps.get(eduId);
            if(employeeinfoFamily==null)
                employeeinfoFamily=employeeService.getEmployeeFamilyById(eduId);
        }else{
            employeeinfoFamily=employeeService.getEmployeeFamilyById(eduId);
        }

        return SUCCESS;
    }

    @Action(value = "/employee/talentedu_delete", results = {
            @Result(name = "success", type = "json")
    })
    public String eduDelete() throws Exception {
        if (state == 1) {
            EmployeeinfoEducation edu = employeeService.getEmployeeinfoEducationById(id);
            if (edu != null)
                employeeService.removeEmpRelate(id, state);
            Object obj = ServletActionContext.getRequest().getSession().getAttribute("eduList");
            Map<Long, EmployeeinfoEducation> edu_maps = (Map<Long, EmployeeinfoEducation>) obj;
            edu_maps.remove(id);
            ServletActionContext.getRequest().getSession().setAttribute("eduList", edu_maps);
        } else if (state == 2) {
            EmployeeinfoTrain train = employeeService.getEmployeeinfoTrainById(id);
            if (train != null)
                employeeService.removeEmpRelate(id, state);
            Object obj = ServletActionContext.getRequest().getSession().getAttribute("trainList");
            Map<Long, EmployeeinfoTrain> train_maps = (Map<Long, EmployeeinfoTrain>) obj;
            train_maps.remove(id);
            ServletActionContext.getRequest().getSession().setAttribute("trainList", train_maps);
        } else if (state == 3) {
            EmployeeWorkExperience exp = employeeService.getEmployeeWorkExperienceById(id);
            if (exp != null)
                employeeService.removeEmpRelate(id, state);
            Object obj = ServletActionContext.getRequest().getSession().getAttribute("expList");
            Map<Long, EmployeeWorkExperience> exp_maps = (Map<Long, EmployeeWorkExperience>) obj;
            exp_maps.remove(id);
            ServletActionContext.getRequest().getSession().setAttribute("expList", exp_maps);
        } else if (state == 4) {
            EmployeeinfoFamily family = employeeService.getEmployeeFamilyById(id);
            if (family != null)
                employeeService.removeEmpRelate(id, state);
            Object obj = ServletActionContext.getRequest().getSession().getAttribute("familyList");
            Map<Long, EmployeeinfoFamily> family_maps = (Map<Long, EmployeeinfoFamily>) obj;
            family_maps.remove(id);
            ServletActionContext.getRequest().getSession().setAttribute("familyList", family_maps);
        }
        return SUCCESS;
    }

    //清除当前会话中的对象
    private void removeSessions() {
        ServletActionContext.getRequest().getSession().removeAttribute("startTime");
        ServletActionContext.getRequest().getSession().removeAttribute("eduList");
        ServletActionContext.getRequest().getSession().removeAttribute("trainList");
        ServletActionContext.getRequest().getSession().removeAttribute("expList");
        ServletActionContext.getRequest().getSession().removeAttribute("familyList");
    }

    public List<Organization> getOrganizations() {
        return organizations;
    }

    public void setOrganizations(List<Organization> organizations) {
        this.organizations = organizations;
    }

    public LimitedList<EmployeeinfoBase> getEmployeeinfoBases() {
        return employeeinfoBases;
    }

    public void setEmployeeinfoBases(LimitedList<EmployeeinfoBase> employeeinfoBases) {
        this.employeeinfoBases = employeeinfoBases;
    }

    public EmployeeinfoBase getEmployeeinfoBase() {
        return employeeinfoBase;
    }

    public void setEmployeeinfoBase(EmployeeinfoBase employeeinfoBase) {
        this.employeeinfoBase = employeeinfoBase;
    }

    public EmployeeinfoEducation getEmployeeinfoEducation() {
        return employeeinfoEducation;
    }

    public void setEmployeeinfoEducation(EmployeeinfoEducation employeeinfoEducation) {
        this.employeeinfoEducation = employeeinfoEducation;
    }

    public EmployeeinfoTrain getEmployeeinfoTrain() {
        return employeeinfoTrain;
    }

    public void setEmployeeinfoTrain(EmployeeinfoTrain employeeinfoTrain) {
        this.employeeinfoTrain = employeeinfoTrain;
    }

    public EmployeeWorkExperience getEmployeeWorkExperience() {
        return employeeWorkExperience;
    }

    public void setEmployeeWorkExperience(EmployeeWorkExperience employeeWorkExperience) {
        this.employeeWorkExperience = employeeWorkExperience;
    }

    public EmployeeinfoFamily getEmployeeinfoFamily() {
        return employeeinfoFamily;
    }

    public void setEmployeeinfoFamily(EmployeeinfoFamily employeeinfoFamily) {
        this.employeeinfoFamily = employeeinfoFamily;
    }

    public List<EmployeeinfoEducation> getEmployeeinfoEducationList() {
        return employeeinfoEducationList;
    }

    public void setEmployeeinfoEducationList(List<EmployeeinfoEducation> employeeinfoEducationList) {
        this.employeeinfoEducationList = employeeinfoEducationList;
    }

    public List<EmployeeinfoTrain> getEmployeeinfoTrains() {
        return employeeinfoTrains;
    }

    public void setEmployeeinfoTrains(List<EmployeeinfoTrain> employeeinfoTrains) {
        this.employeeinfoTrains = employeeinfoTrains;
    }

    public List<EmployeeWorkExperience> getEmployeeWorkExperiences() {
        return employeeWorkExperiences;
    }

    public void setEmployeeWorkExperiences(List<EmployeeWorkExperience> employeeWorkExperiences) {
        this.employeeWorkExperiences = employeeWorkExperiences;
    }

    public List<EmployeeinfoFamily> getEmployeeinfoFamilies() {
        return employeeinfoFamilies;
    }

    public void setEmployeeinfoFamilies(List<EmployeeinfoFamily> employeeinfoFamilies) {
        this.employeeinfoFamilies = employeeinfoFamilies;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getEmpIds() {
        return empIds;
    }

    public void setEmpIds(String empIds) {
        this.empIds = empIds;
    }

    public String getTalentName() {
        return talentName;
    }

    public void setTalentName(String talentName) {
        this.talentName = talentName;
    }

    public StaffSearchPojo getPojo() {
        return pojo;
    }

    public void setPojo(StaffSearchPojo pojo) {
        this.pojo = pojo;
    }

    public Integer getEduSize() {
        return eduSize;
    }

    public void setEduSize(Integer eduSize) {
        this.eduSize = eduSize;
    }

    public Long getEduId() {
        return eduId;
    }

    public void setEduId(Long eduId) {
        this.eduId = eduId;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }


}
